<%--                                                                       --%>
<%-- Copyright (c) 2005 BroadVision, Inc.  All rights reserved.            --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries. Additionally, IONA    --%>
<%-- and Orbix are trademarks of IONA Technologies, Ltd.  RSA, MD5, and    --%>
<%-- RC2 are trademarks of RSA Data Security, Inc.                         --%>
<%--                                                                       --%>

<%@ taglib uri="/WEB-INF/struts-html-el.tld" prefix="html-el" %>
<%@ taglib uri="/WEB-INF/struts-bean-el.tld" prefix="bean-el" %>
<%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>

<%@ page import =  "com.broadvision.web.util.ViewDynaBean,
		    org.apache.struts.validator.DynaValidatorForm,
                    org.apache.commons.beanutils.PropertyUtils,
                    org.apache.struts.action.DynaActionForm,
                    java.util.List"
%>


<script language="javascript">

  var isNav = (navigator.appName.indexOf("Netscape") != -1);
  var isIE = (navigator.appName.indexOf("Microsoft") != -1);
  
  function doUserDeleteAction(theForm, userId) {
    if ( confirm('<bean-el:message key="mt.user.confirm.delete" bundle="mt.messages"/>') ){
      theForm.userId.value = userId;
      theForm.action = '<html-el:rewrite page="/mt/userDelete.do"/>';
      theForm.submit();
      return true;
    }
    return false;
  }
  
  function doUserRemoveFromServiceAction(theForm, userId) {
    if ( confirm('<bean-el:message key="mt.user.confirm.removeFromService" bundle="mt.messages"/>') ){
      theForm.userId.value = userId;
      theForm.action = '<html-el:rewrite page="/mt/userRemoveFromService.do"/>';
      theForm.submit();
      return true;
    }
    return false;
  }
  
  function doUserNewAction(theForm) {
      theForm.action = '<html-el:rewrite page="/mt/userNew.do"/>';
      theForm.submit();
      return true;
  }

  function gotoFirstPage(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      thisForm.currentPageNumber.value = 1;
      thisForm.submit();
      return false;
    }
  }

  function gotoPreviousPage(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      var currentPageNumber = thisForm.currentPageNumber.value;
      currentPageNumber--;
      if (thisForm.entriesPerPage.value != <c:out value="${mtUserSearchForm.map.entriesPerPage}"/>) {
        currentPageNumber = 1;
      }
      if (currentPageNumber > 0) {
        thisForm.currentPageNumber.value = currentPageNumber;
        thisForm.submit();
      }
    }
  }
  
  function gotoNextPage(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      var currentPageNumber = thisForm.currentPageNumber.value;
      currentPageNumber++;
      if (thisForm.entriesPerPage.value != <c:out value="${mtUserSearchForm.map.entriesPerPage}"/>) {
        currentPageNumber = 1;
      }
      if (currentPageNumber <= thisForm.totalPageNumber.value) {
        thisForm.currentPageNumber.value = currentPageNumber;
        thisForm.submit();
      }
    }
  }

  function gotoLastPage(formName) {
    if (doValidateEntriesPerPage(formName) == false) {
      return false;
    }
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      if (thisForm.entriesPerPage.value != <c:out value="${mtUserSearchForm.map.entriesPerPage}"/>) {
        thisForm.currentPageNumber.value = 1;
      }
      else {
        thisForm.currentPageNumber.value = thisForm.totalPageNumber.value;
      }
      thisForm.submit();
    }
  }


  function doGo(formName) {
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      if (thisForm.entriesPerPage.value != <c:out value="${mtUserSearchForm.map.entriesPerPage}"/>) {
        thisForm.currentPageNumber.value = 1;
        thisForm.submit();
      }
    }
    return false;
  }
  
  function checkNumberOnly(e) {
    var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
      return false;
    }
    else {
      return true;
    }
  }

  function doValidateEntriesPerPage(formName) {
    var thisForm = document.forms[formName];
    if (thisForm != null) {
      if (thisForm.entriesPerPage == null) {
        return true;
      }
      var entriesPerPageInt = parseInt(thisForm.entriesPerPage.value);

      if (isNaN(entriesPerPageInt)) {
        alert("<bean-el:message key="mt.common.pagination.validation.itemsPerPage" bundle="mt.messages"/>");
        thisForm.entriesPerPage.select();
        thisForm.entriesPerPage.focus();
        return false;
      }
      if (thisForm.entriesPerPage.value < 1 || thisForm.entriesPerPage.value > 2147483647) {
        alert("<bean-el:message key="mt.common.pagination.validation.itemsPerPage" bundle="mt.messages"/>");
        thisForm.entriesPerPage.select();
        thisForm.entriesPerPage.focus();
        return false;
      }
      else {
        return true;
      }
    }
    return false;
  }  

</script>

<c:set var="editImg">
  <img src="<%= request.getContextPath() %>/mc/images/action/icon_edit.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.edit" bundle="mt.messages"/>" title="<bean-el:message key="image.alt.edit" bundle="mt.messages"/>">
</c:set>
<c:set var="removeImg">
  <img src="<%= request.getContextPath() %>/mc/images/action/icon_remove.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.removeFromService" bundle="mt.messages"/>" title="<bean-el:message key="image.alt.removeFromService" bundle="mt.messages"/>">
</c:set>
<c:set var="deleteImg">
  <img src="<%= request.getContextPath() %>/mc/images/action/icon_delete.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.delete" bundle="mt.messages"/>" title="<bean-el:message key="image.alt.delete" bundle="mt.messages"/>">
</c:set>

<c:if test="${mtUserSearchView.map.searchFor == 'Process'}">
  <c:set var="viewTasksImg">
    <img src="<%= request.getContextPath() %>/bp/images/action/icon_viewtasks.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.tasklist" bundle="bp.messages"/>" title="<bean-el:message key="image.alt.tasklist" bundle="bp.messages"/>">
  </c:set>
  <c:set var="viewDelegationImg">
    <img src="<%= request.getContextPath() %>/bp/images/action/icon_viewdelegates.gif" width="15" height="15" border="0" class="actionIcon" alt="<bean-el:message key="image.alt.delegations" bundle="bp.messages"/>" title="<bean-el:message key="image.alt.delegations" bundle="bp.messages"/>">
  </c:set>
</c:if>

<!-- BEGIN form ( mtUserSearchForm ) -------------------------->

<c:choose>
  <c:when test="${mtUserSearchView.map.searchFor == 'Process'}"> 
    <c:set var="actionVar" value="/bp/userSearch.do" />
  </c:when>
  <c:otherwise>
    <c:set var="actionVar" value="/mt/userSearch.do" />
  </c:otherwise>
</c:choose>

<html-el:form action="${actionVar}" onsubmit="return doGo('mtUserSearchForm');">

<html-el:hidden property="assignRolesMessage"/>
<html-el:hidden property="userId"/>
<html-el:hidden property="currentPageNumber"/>
<html-el:hidden property="totalPageNumber"/>

<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" summary="content area">
  <tr>
    <td valign="top" width="100%">
      <div class="pageTitle">
        <c:if test="${empty mtUserSearchView.map.userList}">
          <bean-el:message key="mt.user.search.page.title" bundle="mt.messages"/>
        </c:if>
        <c:if test="${not empty mtUserSearchView.map.userList}">
          <bean-el:message key="mt.user.search.results.page.title" bundle="mt.messages" arg0="${mtUserSearchView.map.numOfUsers}"/>
        </c:if>
      </div>
      <div class="errorMessage"><html-el:errors bundle="mt.messages" /></div>

      <div class="pageSubtitle">
        <span class="left"><bean-el:message key="mt.search.criteria" bundle="mt.messages"/></span>
        <span class="right">
        	<c:if test="${ empty mtUserSearchView.map.searchFor}">
              <html-el:button styleClass="titleButton" property="submitBtn" onclick="return doUserNewAction(document.mtUserSearchForm);">
                <bean-el:message key="button.createNewUser" bundle="mt.messages"/>
              </html-el:button>
            </c:if>
        </span>
      </div>

      <!- place body here -->

      <table class="labelForm" width="100%" border="0" cellspacing="0" cellpadding="0" summary="Search criteria">
        <tr> 
          <td class="label" width="15%"><bean-el:message key="mt.user.search.label.searchString" bundle="mt.messages"/>:</td>
          <td class="labelField" width="25%"  colspan=3>
                <html-el:radio property="searchStringAnywhere" value="false">
                  <bean-el:message key="mt.user.search.searchBegin" bundle="mt.messages"/>
                </html-el:radio>
                <br>
                <html-el:radio property="searchStringAnywhere" value="true">
                  <bean-el:message key="mt.user.search.searchAnywhere" bundle="mt.messages"/>
                </html-el:radio>
                <br>
          </td>
        </tr>

        <tr>
         <td class="label" width="15%"><bean-el:message key="mt.user.search.label.searchWithin" bundle="mt.messages"/>:</td> 
         <td class="labelField" width="25%"  colspan=3>
           <html-el:radio property="searchEntireSite" value="false">
              <bean-el:message key="mt.user.search.currentService" bundle="mt.messages"/>
           </html-el:radio>
            <br>
                <html-el:radio property="searchEntireSite" value="true">
              <bean-el:message key="mt.user.search.entireSite" bundle="mt.messages"/>
             </html-el:radio>
            <br>
          </td>
        </tr>

        <tr> 
          <td class="label" width="15%"><bean-el:message key="mt.user.label.loginId" bundle="mt.messages"/>:</td>
          <td class="labelField" width="25%">
              <html-el:text property="userAlias" size="25" maxlength="50" />
          </td>
          <td class="label" width="15%">&nbsp;</td>
          <td class="labelField" width="45%">&nbsp;</td>
        </tr>

        <c:choose>
          <c:when test="${mtUserSearchView.map.useFullName}">
            <tr> 
              <td class="label" width="15%"><bean-el:message key="mt.user.label.fullName" bundle="mt.messages"/>:</td>
              <td class="labelField" width="25%">
                <html-el:text property="fullName" size="25" maxlength="50" />
              </td>
              <td class="label" width="15%">&nbsp;</td>
              <td class="labelField" width="45%">&nbsp;</td>
            </tr>
          </c:when>

          <c:otherwise>
            <tr> 
              <td class="label" width="15%"><bean-el:message key="mt.user.label.firstName" bundle="mt.messages"/>:</td>
              <td class="labelField" width="25%">
                <html-el:text property="firstName" size="25" maxlength="50" />
              </td>
              <td class="label" width="15%"><bean-el:message key="mt.user.label.lastName"  bundle="mt.messages"/>:</td>
              <td class="labelField" width="45%">
                <html-el:text property="lastName" size="25" maxlength="50" />
              </td>
            </tr>
          </c:otherwise>
        </c:choose>

        <tr> 
          <td class="label" width="15%"><bean-el:message key="mt.user.label.city" bundle="mt.messages"/>:</td>
          <td class="labelField" width="25%">
            <html-el:text property="city" size="25" maxlength="50" />
          </td>
          <td class="label" width="15%"><bean-el:message key="mt.user.label.state" bundle="mt.messages"/>:</td>
          <td class="labelField" width="45%">
            <html-el:text property="state" size="25" maxlength="50" />
          </td>
        </tr>
        <tr> 
          <td class="label" width="15%"><bean-el:message key="mt.user.label.zipCode" bundle="mt.messages"/>:</td>
          <td class="labelField" width="25%">
            <html-el:text property="zipCode" size="25" maxlength="50" />
          </td>
          <td class="label" width="15%"><bean-el:message key="mt.user.label.country" bundle="mt.messages"/>:</td>
          <td class="labelField" width="45%">
            <html-el:text property="country" size="25" maxlength="50" />
          </td>
        </tr>
        <tr> 
          <td class="label" width="15%"><bean-el:message key="mt.user.label.phone" bundle="mt.messages"/>:</td>
          <td class="labelField" width="25%">
            <html-el:text property="phone" size="25" maxlength="50" />
          </td>
          <td class="label" width="15%"><bean-el:message key="mt.user.label.email" bundle="mt.messages"/>:</td>
          <td class="labelField" width="45%">
            <html-el:text property="email" size="25" maxlength="50" />
          </td>
        </tr>

        <c:if test="${not empty mtUserSearchView.map.organizationList}">
          <tr> 
            <td class="label" width="15%"><bean-el:message key="mt.user.search.label.organization" bundle="mt.messages"/>:</td>
            <td class="labelField" width="25%" colspan=3>
              <c:set var="orgList" scope="page" value="${mtUserSearchView.map.organizationList}"/>
              <html-el:select name="mtUserSearchForm" property="groupFQN"> 
                  <html-el:options collection="orgList" property="groupFQN" labelProperty="name" />
              </html-el:select>
            </td>
          </tr>
        </c:if>
      </table>

      <div class="pageButtonWrap" align="right">
          <input hspace="40" type="submit" name="btn_action" class="pageButton" value="<bean-el:message key="button.showResults" bundle="mt.messages"/>" onclick="javascript:return gotoFirstPage('mtUserSearchForm');">
      </div>
      <br>

<!-- Start Results list here -->

      <c:if test="${mtUserSearchForm.map.searchUsers == 'true'}">

        <%
          ViewDynaBean mtUserSearchView = (ViewDynaBean) request.getAttribute("mtUserSearchView");
          Integer userListLength = (Integer) PropertyUtils.getSimpleProperty(mtUserSearchView, "numOfUsers");
        %>
        <div class="pageSubtitle">
          <span class="left">
            <bean-el:message key="mt.user.searchResult" arg0="<%= userListLength.toString() %>"  bundle="mt.messages"/>
          </span>

          <span class="right"></span>
        </div> 

        <table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="Search result table" width="100%">
          <tr class="listHeader"> 
            <th id="Name" align="left"><bean-el:message key="mt.user.search.header.name" bundle="mt.messages"/></th>
            <th id="LoginId" align="left"><bean-el:message key="mt.user.search.header.loginId" bundle="mt.messages"/></th>
            <th id="City" align="left"><bean-el:message key="mt.user.search.header.city" bundle="mt.messages"/></th>
            <th id="State" align="left"><bean-el:message key="mt.user.search.header.state" bundle="mt.messages"/></th>
            <th id="Phone" align="left"><bean-el:message key="mt.user.search.header.phone" bundle="mt.messages"/></th>
            <th id="Email" align="left"><bean-el:message key="mt.user.search.header.email" bundle="mt.messages"/></th>
            <th id="Actions" align="left" nowrap><bean-el:message key="mt.user.search.header.actions" bundle="mt.messages"/></th>
          </tr>
        <c:choose>
          <c:when test="${not empty mtUserSearchView.map.userList}">
            <c:forEach var="oneUser" items="${mtUserSearchView.map.userList}" varStatus="status">
              <c:choose>
                <c:when test="${(status.count + 1) % 2 == 0}">
	      <tr class="listEven">
                </c:when> 
  	        <c:otherwise>
	      <tr class="listOdd">
	        </c:otherwise>
              </c:choose>

                <td headers="Name">
                  <c:choose>
                    <c:when test="${mtUserSearchView.map.searchFor == 'Process'}">
                      <c:out value="${oneUser.map.formattedName}"/>
                    </c:when>
                    <c:otherwise>
                      <html-el:link page="/mt/userView.do" name="oneUser" property="urlParams">
                        <c:out value="${oneUser.map.formattedName}"/>
                      </html-el:link>
                    </c:otherwise>
                  </c:choose>
                </td>
                <td headers="LoginId"><c:out value="${oneUser.map.userAlias}"/>&nbsp;</td>
                <td headers="City"><c:out value="${oneUser.map.city}"/>&nbsp;</td>
                <td headers="State"><c:out value="${oneUser.map.state}"/>&nbsp;</td>
                <td headers="Phone"><c:out value="${oneUser.map.phone}"/>&nbsp;</td>
                <td headers="Email">
                  <c:if test="${!empty oneUser.map.email}">
                    <a href="mailto:<c:out value='${oneUser.map.email}'/>"><c:out value="${oneUser.map.email}"/></a>
                  </c:if>&nbsp;
                </td>
                <td nowrap align="left" headers="Actions">
                  <c:choose>
                    <c:when test="${mtUserSearchView.map.searchFor == 'Process'}">
                      <html-el:link page="/bp/taskList.do" name="oneUser" property="urlParams"><c:out value='${viewTasksImg}' escapeXml="false"/></html-el:link>
                      <html-el:link page="/bp/delegationList.do" name="oneUser" property="urlParams"><c:out value='${viewDelegationImg}' escapeXml="false"/></html-el:link>
                    </c:when>
                    <c:otherwise>
                      <c:if test="${mtUserSearchView.map.canEdit}">
                        <html-el:link page="/mt/userEdit.do" name="oneUser" property="urlParams"><c:out value='${editImg}' escapeXml="false"/></html-el:link>
                        <c:if test="${oneUser.map.canRemoveFromService}">
                          <a href="#" onclick="return doUserRemoveFromServiceAction(document.mtUserSearchForm, '<c:out value="${oneUser.map.userId}"/>');"><c:out value='${removeImg}' escapeXml="false"/></a>
                        </c:if>
                        <c:if test="${oneUser.map.canDelete}" >
                          <a href="#" onclick="return doUserDeleteAction(document.mtUserSearchForm, '<c:out value="${oneUser.map.userId}"/>');"><c:out value='${deleteImg}' escapeXml="false"/></a>
                        </c:if>
                      </c:if>
                    </c:otherwise>
                  </c:choose>
                </td>
              </tr>
            </c:forEach>
          </c:when>
            <c:otherwise>
              <tr class="listOdd">
                <td colspan=7 align="center"><bean-el:message key="mt.user.search.noUser" bundle="mt.messages"/></td>
              </tr>
            </c:otherwise>
          </c:choose>
        </table>
      </c:if>

<!--End list here-->
      <html-el:hidden property="searchUsers" value="true"/>

      <c:if test="${mtUserSearchView.map.numOfUsers > 0}">
        <div class="pagination">

          <bean-el:message key="page.show" bundle="mt.messages"/>
          <html-el:select property="entriesPerPage" size="1"  onchange="javascript:doGo('mtUserSearchForm')">
            <html-el:option value="10">10</html-el:option>
            <html-el:option value="20">20</html-el:option>
            <html-el:option value="30">30</html-el:option>
            <html-el:option value="50">50</html-el:option>
            <html-el:option value="100">100</html-el:option>
          </html-el:select>
          <bean-el:message key="page.itemsPerPage" bundle="mt.messages"/>
          &nbsp;&nbsp;

          <c:if test="${mtUserSearchForm.map.totalPageNumber > 1}">
            &nbsp;&nbsp;&nbsp;
            <c:if test="${mtUserSearchForm.map.currentPageNumber > 0}">
              <c:if test="${mtUserSearchForm.map.totalPageNumber > 1}">
                <c:if test="${mtUserSearchForm.map.currentPageNumber > 1}">
                  <a href="#" class="paginationBtn" onclick="javascript:gotoFirstPage('mtUserSearchForm')">
                    <bean-el:message key="page.first" bundle="mt.messages"/></a>
                  <a href="#" class="paginationBtn" onclick="javascript:gotoPreviousPage('mtUserSearchForm')">
                    <bean-el:message key="page.previous" bundle="mt.messages"/></a>
                </c:if>
              </c:if>
              <c:set var="currentPageNumberAttr" scope="page" value="${mtUserSearchForm.map.currentPageNumber}"/>
              <c:set var="totalPageNumberAttr" scope="page" value="${mtUserSearchForm.map.totalPageNumber}"/>
              <% Integer currentPageNumberInt = (Integer)pageContext.getAttribute("currentPageNumberAttr"); %>
              <% Integer totalPageNumberInt = (Integer)pageContext.getAttribute("totalPageNumberAttr"); %>
              <bean-el:message key="page.pageOf" 
                arg0="<%= currentPageNumberInt.toString() %>" 
                arg1="<%= totalPageNumberInt.toString() %>" bundle="mt.messages"/>
              <c:if test="${mtUserSearchForm.map.totalPageNumber > 1}">
                <c:if test="${mtUserSearchForm.map.currentPageNumber < mtUserSearchForm.map.totalPageNumber}">
                  <a href="#" class="paginationBtn" onclick="javascript:gotoNextPage('mtUserSearchForm')">
                    <bean-el:message key="page.next" bundle="mt.messages"/></a>
                  <a href="#" class="paginationBtn" onclick="javascript:gotoLastPage('mtUserSearchForm')">
                    <bean-el:message key="page.last" bundle="mt.messages"/></a>
                </c:if>
              </c:if>
            </c:if>
          </c:if>
        </div>
      </c:if>
    </td>
  </tr>
</table>

</html-el:form>

<!-- END form ( mtUserSearchForm ) -------------------------->
